package com.vincent.sciinfo.service.impl;

import com.vincent.sciinfo.mapper.UserMapper;
import com.vincent.sciinfo.pojo.User;
import com.vincent.sciinfo.pojo.UserExample;
import com.vincent.sciinfo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean checkUser(String userId) {
        UserExample userExample = new UserExample();
        UserExample.Criteria circle = userExample.createCriteria();
        circle.andUserIdEqualTo(userId);
        return userMapper.selectByExample(userExample).size() == 0 ? false : true;
    }

    @Override
    public User getUserById(User user) {
        return userMapper.selectByPrimaryKey(user.getUserId());
    }

    @Override
    public int updatePassword(String userId, String password) {
        User user = new User();
        user.setUserId(userId);
        user.setUserPaswd(password);
        return userMapper.updateById(user);
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }
}
